﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Data.OleDb;

using System.Web.Configuration;
using System.Management;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
using System.IO;
using System.Web.Security;
using System.Timers;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Web.Mail;



public partial class Home_buy : System.Web.UI.Page
{

      
    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    ///<summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///</summary>
    private void InitializeComponent()
    {
    this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
    this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] == null)
            Response.Redirect("login.aspx");

        if (!this.IsPostBack) LoadData();

        DataList1.DataSource = users.View_sp();
        DataList1.DataBind();
        //DataList2.DataSource = users.View_chitiet(id);
        //DataList2.DataBind();

        DateTime dt;
        dt = DateTime.Now;
        long tg;
        int songay;
        int sogio;
        int sophut;
        int sophutconlai;
        int id = 34;
       
        tg = Dao.nam_thang_ngay_gio_phut(dt, users.Nam(id),users.Thang(id),users.Ngay(id),users.Gio(id),users.Phut(id));
        songay = (int)tg / (60 * 24);
        sophutconlai = (int)(tg % (60 * 24));
        sogio = sophutconlai / 60;
        sophut = (int)(sophutconlai % 60);
        if (songay != 0 && sogio != 0 && sophut != 0)
            Lbgio.Text = "Thời gian còn lại:" + songay + "Ngày" + "," + sogio + "Giờ" + "," + sophut + "Phút";
        if (songay == 0)
            Lbgio.Text = "Thời gian còn lại:" + sogio + "Giờ" + "," + sophut + "Phút";
        if (sogio == 0)
            Lbgio.Text = "Thời gian còn lại:" + sophut + "Phút";
        if (sophut == 0)
            Lbgio.Text = "Thời gian còn lại:" + sogio + "Giờ";


    }

    private void LoadData()
    {
        const int NUM_ROWS_PER_PAGE = 9;

        try
        {

            string sql = "SB001";
            int index = int.Parse(TextBox2.Text);
            DataSet Ds=Dao.Get_Thongtin(index,NUM_ROWS_PER_PAGE,sql);
            DataList1.DataSource =Ds.Tables["SB001"].DefaultView;
            DataList1.DataBind();
           

            
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message.ToString());
        }
    }

   
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        int index = int.Parse(TextBox2.Text);
        index++;
        //if(index)
        TextBox2.Text = index.ToString();
        LoadData();
        

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        int index = int.Parse(TextBox2.Text);
        index--;
        if (index >= 0)
        {
            TextBox2.Text = index.ToString();
            LoadData();
        }
        else
            index = 0;

    }
}
